package com.shop.shop_end.controller;

import com.shop.shop_end.entity.Order;
import com.shop.shop_end.entity.User;
import com.shop.shop_end.service.OrderService;
import com.shop.shop_end.service.UserService;
import com.shop.shop_end.utils.PageHelper;
import com.shop.shop_end.utils.result.Result;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author
 * @since 2024-04-23
 */
@RestController
@RequestMapping("/order")
public class OrderController {
    @Resource
    private OrderService orderService;

    @Resource
    private UserService userService;

    // 添加数据
    @RequestMapping("/addOrder")
    public Result addOrder(@RequestBody Order order) {
        return orderService.addOneOrder(order);
    }

    /**
     * 更新订单
     * @param order
     * @return
     */
    @RequestMapping("/updateOrder")
    public Result updateOrder(@RequestBody Order order) {
        return orderService.updateOrder(order);
    }

    // 通过主键删除数据
    @RequestMapping("/deleteOrderById/{id}")
    public Result deleteOrderById(@PathVariable("id") Long id) {
        return this.orderService.deleteOrderById(id);
    }

    /**
     * 更新订单状态，发货
     */
    @RequestMapping("/status/{id}/{status}")
    public Result setOrderStatus(@PathVariable("id") Long orderId, @PathVariable("status") String status){
        return orderService.setOrderStatus(orderId, status);
    }
}
